package com.enjoyor.soa.traffic.rest.tsms.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.tsms.CommonPlaceDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.tsms.dubbo.ICommonPlaceConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

@Auth
@RestController
@RequestMapping({ "/CommonPlace" })//getCommonPlacePage
@Api("CommonPlaceController相关api")
@CrossOrigin
public class CommonPlaceController {
	
	
	@Autowired ICommonPlaceConsumeService iCommonPlaceConsumeService;
	
	/**
	 * 常备单位-常备单位分页
	 * @param page 分页参数
	 * @return zyh
	 */
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @GetMapping(value = { "/getCommonPlacePage" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("常备单位分页")
    	@ApiImplicitParams({
        @ApiImplicitParam(name = "commonPlaceId", value = "常备单位编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "commonPlaceName", value = "常备单位名称", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "placeTypeId", value = "单位性质编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "placeTypeName", value = "单位性质名称", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "placeAddress", value = "单位地址", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "createPerson", value = "创建人", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "placePerson", value = "联系人", paramType = "query", dataType = "string") })
    public ResultPojo getCommonPlacePage(
    		@RequestParam(defaultValue = "") String commonPlaceId, 
			@RequestParam(defaultValue = "") String commonPlaceName,
			@RequestParam(defaultValue = "") String placeTypeId, 
			@RequestParam(defaultValue = "") String placeTypeName, 
			@RequestParam(defaultValue = "") String placeAddress,
			@RequestParam(defaultValue = "") String createPerson, 
			@RequestParam(defaultValue = "") String createTime, 
			@RequestParam(defaultValue = "") String placePerson, 
    		Page page, HttpServletRequest request){
    	
    	ResultPojo resultPojo = new ResultPojo();
		resultPojo = iCommonPlaceConsumeService.getCommonPlacePage(page, commonPlaceId, commonPlaceName, placeTypeId,
				placeTypeName, placeAddress, createPerson, createTime, placePerson);
		return resultPojo;
    }
    
    /**
	 * 获取常备单位List；
	 * @return zyh
	 */
	@GetMapping(value = { "/getCommonPlaceList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	//@ApiResponse(response=CommonPlaceDto.class, code = 0, message = "")
    @ApiOperation("常备单位列表信息查询")
	@ApiImplicitParams({
        @ApiImplicitParam(name = "commonPlaceId", value = "常备单位编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "commonPlaceName", value = "常备单位名称", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "placeTypeId", value = "单位性质编号", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "placeTypeName", value = "单位性质名称", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "placeAddress", value = "单位地址", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "createPerson", value = "创建人", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query", dataType = "string"),
        @ApiImplicitParam(name = "placePerson", value = "联系人", paramType = "query", dataType = "string") })
	public ResultPojo getCommonPlaceList(
			@RequestParam(defaultValue = "") String commonPlaceId, 
			@RequestParam(defaultValue = "") String commonPlaceName,
			@RequestParam(defaultValue = "") String placeTypeId, 
			@RequestParam(defaultValue = "") String placeTypeName, 
			@RequestParam(defaultValue = "") String placeAddress,
			@RequestParam(defaultValue = "") String createPerson, 
			@RequestParam(defaultValue = "") String createTime, 
			@RequestParam(defaultValue = "") String placePerson, 
    		HttpServletRequest request) {
		ResultPojo resultPojo = new ResultPojo();
		resultPojo = iCommonPlaceConsumeService.getCommonPlaceList(commonPlaceId, commonPlaceName, placeTypeId,
				placeTypeName, placeAddress, createPerson, createTime, placePerson);
		return resultPojo;
	}
	
	/**
	 * 
	 * @param commonPlaceDto
	 * @param request
	 * @return
	 */
	@PostMapping(value = { "/addCommonPlace" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("添加常备单位")
	public ResultPojo addCommonPlace(@RequestBody CommonPlaceDto commonPlaceDto, HttpServletRequest request) {
			return iCommonPlaceConsumeService.insert(commonPlaceDto,((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	
	@PutMapping(value = { "/editCommonPlace" }, consumes = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("修改常备单位")
	public ResultPojo editCommonPlace(@RequestBody CommonPlaceDto commonPlaceDto, HttpServletRequest request) {
			return iCommonPlaceConsumeService.update(commonPlaceDto,((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	
	@DeleteMapping(value = { "/delCommonPlace" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("删除常备单位")
    @ApiImplicitParam(name = "commonPlaceId", value = "常用单位编号", paramType = "query", required = true, dataType = "String")
    public ResultPojo delCommonPlace(
    		@RequestParam(defaultValue = "",value="commonPlaceId", required=true) String commonPlaceId,
    		HttpServletRequest request) {
        return iCommonPlaceConsumeService.delete(commonPlaceId, ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	
}
